import random

def roulette_wheel_A(E):
	sumE = 0
	for e in E:
		sumE += e
	
	r = random.randint(1,sumE)
	
	for i in range(len(E)):
		r -= E[i]
		if r <= E[i]:
			return i
			

def roulette_wheel_B(E):
	sumE = 0
	for e in E:
		sumE += e
	
	r = random.randint(1,sumE)
	i = -1
	while True:
		i+=1
		sumE -= E[i]
		if sumE < r:
			return i

def roulette_wheel_C(E):
	sumE = 0
	for e in E:
		sumE += e
	
	sum_aux = 0
	r = random.randint(1,sumE)
	
	for i in range(len(E)):
		sum_aux += E[i]
		if r <= sum_aux:
			return i
	
#E = [5,5,5,4,3,2,1,1,1,1]
E = [1,1,1,1,2,3,4,5,5,5]

for i in range(1000000):
	random.shuffle(E)
	print roulette_wheel(E)
